package com.tim.third;

import org.dom4j.Document;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

import java.io.IOException;
import java.io.StringWriter;

/**
 * xml解析
 * dom4j
 *
 */
public class Dom4jXmlUtil {

    public static String formatDocument(Document document) throws IOException {
        StringWriter stringWriter = new StringWriter();
        OutputFormat format = OutputFormat.createPrettyPrint();
        XMLWriter writer = new XMLWriter(stringWriter, format);
        writer.write(document);
        writer.flush();
        String content = stringWriter.getBuffer().toString();
        return content;
    }
}
